package com.xinwei.leetcode.数组;

import sun.awt.image.ImageWatched;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

// https://leetcode-cn.com/problems/subsets/
// 这道题感觉和77题有点像
public class _78_子集 {
    List<List<Integer>> lists = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        Deque deque = new LinkedList<Integer>();
        dfs(-1, nums, deque);
        return lists;
    }

    private void dfs(int cur, int[] nums, Deque deque) {
        if (cur == nums.length) return;
        lists.add(new ArrayList<>(deque));
        for (int i = cur + 1; i < nums.length; i++) {
            deque.push(nums[i]);
            dfs(i, nums, deque);
            deque.pop();
        }
    }
}
